<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml">

	<f:metadata>
		<f:event type="preRenderView" listener="#{scheduleBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form prependId="false">

			<p:schedule value="#{scheduleBean.scheduleModel}" resizable="false" draggable="false" widgetVar="myschedule"
				locale="pt">
				<p:ajax event="eventSelect" listener="#{scheduleBean.onEventSelect}"
					update="eventDetails,eventDetailsMedicao,eventDetailsAvaliacao,eventDetailsItem" />

			</p:schedule>


			<p:dialog appendToBody="false" widgetVar="medicaoDialog" id="eventDetailsMedicao" header="Medição" resizable="false"
				width="650" height="250" showEffect="explode" hideEffect="explode">

				<h:panelGrid columns="4" id="panelExibicaoMedicao" columnClasses="coluna20,coluna30,coluna25,coluna25" width="100%">
					<h:outputLabel value="Animal" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.animal.nome}" />
					<h:outputLabel value="Parte de Medição" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.parteMedicao.descricao}" />
					<h:outputLabel value="Unidade de medida" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.unidadeMedida.descricao}" />
					<h:outputLabel value="Medida" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.valor}" />
					<h:outputLabel value="Data Cadastro" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.dtCadastro}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:panelGrid>
				<h:panelGrid columns="2" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Observação" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.observacao}" />
				</h:panelGrid>
			</p:dialog>
			<p:dialog appendToBody="false" widgetVar="itemEntradaDialog" id="eventDetailsItem" header="Item Entrada"
				resizable="false" width="650" height="250" showEffect="explode" hideEffect="explode">

				<h:panelGrid columns="4" columnClasses="coluna20,coluna30,coluna25,coluna25" width="100%">
					<h:outputLabel value="Nota Fiscal" />
					<h:outputText value="#{scheduleBean.itemEntrada.entrada.notaFiscal}" />
					<h:outputLabel value="Fornecedor" />
					<h:outputText value="#{scheduleBean.itemEntrada.entrada.fornecedor.razaoSocial}" />
					<h:outputLabel value="Produto" />
					<h:outputText value="#{scheduleBean.itemEntrada.produto.descricao}" />
					<h:outputLabel value="Marca" />
					<h:outputText value="#{scheduleBean.itemEntrada.marca.descricao}" />
					<h:outputLabel value="Quantidade" />
					<h:outputText value="#{scheduleBean.itemEntrada.quantidade}" />
					<h:outputLabel value="Valor" />
					<h:outputText value="#{scheduleBean.itemEntrada.valor}" />
					<h:outputLabel value="% Lucro" />
					<h:outputText value="#{scheduleBean.itemEntrada.porcetagemLucro}" />
					<h:outputLabel value="Valor Final" />
					<h:outputText value="#{scheduleBean.itemEntrada.valorFinal}" />
					<h:outputLabel value="Data de Validade" />
					<h:outputText value="#{scheduleBean.itemEntrada.dtValidade}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:panelGrid>
			</p:dialog>
			<p:dialog appendToBody="false" widgetVar="avaliacaoDialog" id="eventDetailsAvaliacao" header="Avaliação"
				resizable="false" width="650" height="400" showEffect="explode" hideEffect="explode">

				<h:panelGrid columns="4" id="panelExibicaoAvaliacao" columnClasses="coluna20,coluna30,coluna25,coluna25"
					width="100%">
					<h:outputLabel value="Animal" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.animal.nome}" />
					<h:outputLabel value="Usuário" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.usuario.nome}" />
					<h:outputLabel value="Situação Casco" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.avaliacaoCasco.descricao}" />
					<h:outputLabel value="Avaliação Dentição" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.avaliacaoDenticao.descricao}" />
					<h:outputLabel value="Peso" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.peso}" />
					<h:outputLabel value="Circ. Toráxica" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.cincurferencia}" />
					<h:outputLabel value="Data Cadastro" />
					<h:outputText value="#{scheduleBean.medicaoAnimal.dtCadastro}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:panelGrid>
				<h:panelGrid columns="2" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Observação Dentição" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.denticao}" />
					<h:outputLabel value="Informação Nutricional" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.nutricional}" />
					<h:outputLabel value="Situação do Caso" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.situacaoCasco}" />
					<h:outputLabel value="Observação" />
					<h:outputText value="#{scheduleBean.avaliacaoAnimal.observacao}" />
				</h:panelGrid>
			</p:dialog>

			<p:dialog appendToBody="false" widgetVar="manejoDialog" id="eventDetails" header="Manejo" resizable="false"
				width="650" height="520" showEffect="explode" hideEffect="explode">

				<p:toolbar rendered="#{scheduleBean.manejo.statusAtual.statusExecucao.id == 4}">
					<p:toolbarGroup align="left">
						<p:commandButton value="Cancelar"
							rendered="#{scheduleBean.manejo.statusAtual.statusExecucao.id == 4 and p:ifGranted('ROLE_MANEJO_CANCELAR')}"
							title="Cancelar" oncomplete="confirmationCancelar.show()">
						</p:commandButton>
						<p:spacer width="10" />
						<p:commandButton value="Finalizar"
							rendered="#{scheduleBean.manejo.statusAtual.statusExecucao.id == 4 and p:ifGranted('ROLE_MANEJO_FINALIZAR')}"
							title="Finalizar" oncomplete="confirmationFinalizar.show()">
						</p:commandButton>
					</p:toolbarGroup>
				</p:toolbar>
				<br />

				<h:panelGrid columns="4" id="panelExibicao" columnClasses="coluna20,coluna30,coluna25,coluna25" width="100%">
					<h:outputLabel value="Animal" />
					<h:outputText value="#{scheduleBean.manejo.animal.nome}" />
					<h:outputLabel value="Executor" />
					<h:outputText value="#{scheduleBean.manejo.usuarioExecutor.nome}" />
					<h:outputLabel value="Avaliador" />
					<h:outputText value="#{scheduleBean.manejo.usuarioAvaliador.nome}" />
					<h:outputLabel value="Tipo Tarefa" />
					<h:outputText value="#{scheduleBean.manejo.tipoTarefa.descricao}" />
					<h:outputLabel value="Data de Início" />
					<h:outputText value="#{scheduleBean.manejo.dtInicioString}" />
					<h:outputLabel value="Data de Término" />
					<h:outputText value="#{scheduleBean.manejo.dtFimString}" />
					<h:outputLabel value="Status" />
					<h:outputText value="#{scheduleBean.manejo.statusAtual.statusExecucao.descricao}" />
				</h:panelGrid>
				<h:panelGrid columns="2" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Observação" />
					<h:outputText value="#{scheduleBean.manejo.observacao}" />
				</h:panelGrid>
				<h:panelGrid columns="2" columnClasses="coluna20,coluna80" width="100%"
					rendered="#{scheduleBean.manejo.statusAtual.statusExecucao.id != 4}">
					<h:outputLabel value="Motivo" />
					<h:outputText value="#{scheduleBean.manejo.statusAtual.motivo}" />
				</h:panelGrid>
				<br />
				<p:dataTable var="produtos" id="listaProdutos" emptyMessage="#{scheduleBean.emptyMessage}" update="listaProdutos"
					styleClass="coluna100" value="#{scheduleBean.manejo.manejoProdutos}" paginator="true" rows="5"
					rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}" rowIndexVar="rowIx">
					<p:column headerText="Produto" style="width:40%">
						<h:outputLabel value="#{produtos.produto.descricao}" />
					</p:column>
					<p:column headerText="Unidade de medida" style="width:40%">
						<h:outputLabel value="#{produtos.unidadeMedida.descricao}" />
					</p:column>
					<p:column headerText="Quantidade" style="width:10%">
						<h:outputLabel value="#{produtos.qtdUso}" />
					</p:column>
				</p:dataTable>
			</p:dialog>

			<p:dialog appendToBody="false" header="Finalizar" widgetVar="confirmationFinalizar" width="400" height="150">
				<br />
				<h:panelGrid columns="2" id="panelFinalizar" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Motivo:" />
					<p:inputTextarea cols="40" rows="4" value="#{scheduleBean.motivoFinalizar}" id="motivoFinal" />
				</h:panelGrid>
				<br />
				<br />
				<div align="center">
					<p:commandButton value="Salvar" ajax="false" oncomplete="confirmationFinalizar.hide()"
						action="#{scheduleBean.finalizarManejo}" />
					<p:commandButton value="Fechar" onclick="confirmationFinalizar.hide()" />
				</div>
			</p:dialog>

			<p:dialog appendToBody="false" header="Cancelamento" widgetVar="confirmationCancelar" width="400" height="150">
				<br />
				<h:panelGrid columns="2" id="panelCancelar" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Motivo:" />
					<p:inputTextarea cols="40" rows="4" value="#{scheduleBean.motivoCancelar}" id="motivo" />
				</h:panelGrid>
				<br />
				<br />
				<div align="center">
					<p:commandButton value="Salvar" ajax="false" oncomplete="confirmationCancelar.hide()"
						action="#{scheduleBean.cancelarManejo}" />
					<p:commandButton value="Fechar" onclick="confirmationCancelar.hide()" />
				</div>
			</p:dialog>


		</h:form>
	</ui:define>
</ui:composition>